<template>
    <div class="w-100 h-100" style="position: relative">
      <div
        style="width: 100%; height: 10%; position: absolute; top: 0; right: 0"
        class="d-flex justify-content-end"
      >
        <FakeLegend
          style="margin: auto 30px auto 0px"
          :color="colorSingleList"
          :text="['在线', '离线']"
        >
        </FakeLegend>
      </div>
      <div class="bottom">
        <div id="sbyxzt" style="width: 100%; height: 100%"></div>
      </div>
    </div>
  </template>
  
  <script setup lang="ts">
  import * as echarts from "echarts";
  import { useOptions } from "@/hook/useOptions";
  import FakeLegend from "@/components/project/fakeLegend.vue";
  import {chartOptions} from '@/hook/chartOptions' 
  const colorSingleList = ["rgba(3, 230, 254, 1)", "rgba(184, 235, 143, 1)"];
  
  
  const jsonData: any = inject("jsonData");

  
  const current = computed(() => {
    let data = [[], []];
    try {
       data = jsonData.value.yxjk.sbyxzt    
    } catch (error) {}
  
    return data;
  });
  let myChart1: any;
  
  watch(
    () => current.value,
    (val) => {
      if (val) {
        myChart1.setOption({
          series: [{ data: val[0] }, { data: val[1] }],
        });
      }
    }
  );
  
  
  onMounted(() => {
    const option:any = chartOptions().twoBarOption(echarts, ['在线', '离线'])
    option.xAxis[0].data = useOptions().deviceList.map((item) => item.label);
    option.yAxis[0].name = '个'
    myChart1 = echarts.init(document.getElementById("sbyxzt") as HTMLElement);
    myChart1.setOption(option);
  });
  </script>
  
  <style lang="less" scoped>
  .bottom {
    width: 100%;
    height: 100%;
    display: flex;
  }
  </style>
  